package com.itCar.base.tools.excel;

import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @ClassName Test
 * @Description TODO
 * @Author liuzhiguo
 * @Date 2024/8/24 9:09
 * @Version 1.0
 */
public class Test {

    public static void main(String[] args) throws Exception {
//        MultipartFile file = fileInputStreamToMultipartFile("C:\\Users\\amnes\\Desktop\\用户表.xlsx", "file.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
//        List<TestUser> users = ExcelUtils.readMultipartFile(file, TestUser.class);
//        for (TestUser user : users) {
//            System.out.println(user.toString());
//            System.out.println(user.getName());
//        }
//        ExcelReader reader = null;
//        try {
//            reader = ExcelUtil.getReader(file.getInputStream());
//        } catch (IOException e) {
//            log.error("读取文件错误: " + e.getMessage());
//        }
//        if (null == reader) {
//            throw new ValidException("未读取到文件数据");
//        }
//        List<Map> list = reader.readAll(Map.class);
//        if (null == list || list.size() == 0) {
//            System.out.println("11");
//        }
//        for (Map item : list) {
//            TestUser user = new TestUser(item);
//            System.out.println(user);
//        }

        int pointsDataLimit = 500;
        int i = 500 / pointsDataLimit + 1;
        System.out.println(i);

    }

    public static MultipartFile fileInputStreamToMultipartFile(String filePath, String fileName, String contentType) throws IOException {
        FileInputStream inputStream = new FileInputStream(filePath);
        return new MockMultipartFile(fileName, fileName, contentType, inputStream);
    }
//    public int importData(List<CivilAirDefenseFacilities> list) {
//        int pointsDataLimit = 500;
//        List<CivilAirDefenseFacilities> newList = new ArrayList<>();
//        List<String> result = new ArrayList<>();
//        for (int i = 0; i < list.size(); i++) { // 分批次处理
//            newList.add(list.get(i));
//            if (pointsDataLimit == newList.size() || i == list.size() - 1) {
//                // 执行批量新增
//                boolean flag = mapper.insertData(newList);
//                result.add("" + flag + "");
//                // 执行插入历史数据
//                boolean history_flag = mapper.insertHistoryData(newList);
//                result.add("" + history_flag + "");
//
//                newList.clear();
//            }
//        }
//        if (result.contains("false")) {
//            throw new ValidException("导入失败");
//        }
//        return list.size();
//    }

}
